#ifndef _HEAD_H_
#define _HEAD_H_
//#include "threadPool.h"
//#include "queue.h"

#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include <pwd.h>
#include <grp.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <syslog.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/wait.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <signal.h>
#include <pthread.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/epoll.h>
#include <sys/sendfile.h>
#include <mysql/mysql.h>
#include <openssl/md5.h> 

#define ARGS_CHECK(argc,num) {if(argc != num){\
        fprintf(stderr,"Args error!\n");\
        return -1;}}
#define ERROR_CHECK(ret,num,msg) {if(ret==num){\
        perror(msg);\
        return -1;}}
#define THREAD_ERROR_CHECK(ret,funcName) \
        do {if(0!=ret){ printf("%s:%s\n",funcName,\
        strerror(ret));\
        }}while(0)


enum{
    CD      = 0x1000,
    LS      = 0x1001,
    PWD     = 0x1002,
    RM      = 0x1003,
    MKDIR   = 0x1004,
    PUTS    = 0x1005,
    GETS    = 0x1006,
    MESSAGE = 0x1007, //服务器传给客户端的显示信息

    FILE_SIZE   = 0x2001,  //传输文件的大小
    FILE_DATA   = 0x2002,  //实际传输的文件内容
    FILE_MD5    = 0x2003,  //文件的MD5值
    FILE_OFFSET = 0x2004,   //文件偏移
    FILE_NAME   = 0x2005  //文件名
};

typedef struct{
    int  type; //传输的文件类型
    int  size; //data的大小
    char data[]; //实际使用的信息
}protocol_t;


typedef struct{
    int  usr_id;//用户ID
    char* pwd;//用户当前工作目录
    char* token;//token值
}usr_info_t;

//cd  
int changeDirectory(MYSQL* conn,usr_info_t *usr,char *dir);

//ls
int listFile(MYSQL* conn,usr_info_t usr,protocol_t *data);

//pwd
int printWorkingDirectorychar(usr_info_t usr,protocol_t *data);

//rm
int removeFile(MYSQL *conn,usr_info_t usr,protocol_t *data);

//mkdir
int makeDirectory(MYSQL *conn,usr_info_t usr,protocol_t *data);

//download
int getFile(MYSQL *conn,usr_info_t usr,protocol_t *data);

//upload
int putFile(MYSQL *conn,usr_info_t usr,protocol_t *data);

//登录
int logIn(MYSQL *conn,usr_info_t *usr,char* usr_name,char* passwd,protocol_t *data);

//注册
int registers(MYSQL *conn,char* usr_name,char* passwd);

//文件传输
int transfile(int client_fd,char *filename);

//断点续传
int dotTransfile(int client_fd,char *filename,int  off,char *md5);

//日志记录
int logs(usr_info_t usr,protocol_t data);
  
//大文件传输
int bigFile(int client_fd,char *filenamen);




#endif

